
package it.giuseppefrattura.wwdefence;

import java.util.ArrayList;

import org.andengine.entity.modifier.MoveModifier;
import org.andengine.entity.modifier.SequenceEntityModifier;

//import android.util.Log;

public class EnemyLogic {
	public int hp=0;
	float px,py=0;
	
	public EnemyLogic(int _hp, float _px, float _py){
		this.hp=_hp;
		this.px=_px;
		this.py=_py;
	}
	
	public void colpito() {
        synchronized (this) {hp--;}
    }

    public boolean dead(){
    	return (hp<=0);
    }

    public SequenceEntityModifier sposta(char[][] v){
    	ArrayList<MoveModifier> array = new ArrayList<MoveModifier>();
    	float pFromX=this.px;
    	float pFromY=this.py;
    	float pToX=pFromX;
    	float pToY=pFromY;
	    for (int i=0; i<8; i++){
	    	for (int k=0; k<8; k++){
	    		if (v[k][i]!='N'){
	    			switch (v[k][i]){
	    				case 'A':
	    					if (i==7) pToX = pFromX + 150;
	    	   			 	else pToX = pFromX + 100;
	    					break;
	    				case 'S':
	    					pToY = pFromY + 60;
	    					break;
	    				case 'U':
	    					pToY = pFromY - 60;
	    					break;
	    				case 'I':
	    					pToX = pFromX - 100;
	    					break;
	    			}
	    			array.add(new MoveModifier(1f, pFromX, pToX, pFromY, pToY));
	    			pFromX=pToX;pFromY=pToY;
	    		}
	    	}
	    }
	    MoveModifier[] ma = (MoveModifier[]) array.toArray(new MoveModifier[array.size()]);
	    return new SequenceEntityModifier(ma);
	 }   
}

